package com.huawang.mdesign.model.service.constant;

import com.huawang.business.constants.ErrorCode;
import com.huawang.business.constants.ModelActionName;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author cdl
 */
@AllArgsConstructor
@Getter
public enum ModelActionEnum {

    ADD_MODEL(ModelActionName.ADD_MODEL, ErrorCode.ADD_MODEL_ERROR),
    UPDATE_MODEL(ModelActionName.UPDATE_MODEL, ErrorCode.UPDATE_MODEL_ERROR),
    DELETE_MODEL(ModelActionName.DELETE_MODEL, ErrorCode.DELETE_MODEL_ERROR),
    ;

    private final String action;

    private final ErrorCode error;

    @NotNull
    public static ErrorCode getErrorCode(String action) {
        return Arrays.stream(ModelActionEnum.values())
                .filter(e -> Objects.equals(e.action, action))
                .findFirst()
                .map(ModelActionEnum::getError)
                .orElse(ErrorCode.ADD_MODEL_ERROR);
    }
}
